package medium除自身的乘数;

public class Solution {
    public int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] right = new int[n];
        int[] left = new int[n];
        for (int i = 0, j = n-1; i < n && j >= 0; i++, j--) {
            if (i == 0 && j == n-1){
                right[i] = 1;
                left[j] = 1;
            }
            else {
                right[i] = right[i-1]*nums[i-1];
                left[j] = left[j+1]*nums[j+1];
            }
        }
        for (int i = 0; i < n; i++) {
            nums[i] = right[i]*left[i];
        }
        return nums;
    }
}
